using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum RectTramsformProperty
{
    Pivot_x,
    Pivot_y,
    Rotate,
    Scale_x,
    Scale_y,
    Scale_z,
    Scale_xyz,
}

[Serializable]
public class RectTransformAnim : EasyAnimBase
{
    public RectTramsformProperty property;
    public AnimationCurve curve;
    public RectTransform rectTransform;
}

public class RectTransformAnimation : EasyAnimation<RectTransformAnim>
{
    protected override void Awake()
    {
        base.Awake();
        for (int i = 0; i < anims.Length; i++)
        {
            anims[i].rectTransform = anims[i].targetObject.GetComponent<RectTransform>();
        }
    }

    protected override void ApplyAnim(RectTransformAnim anim, float process)
    {
        float val = anim.curve.Evaluate(process) * anim.multiply;

        switch (anim.property)
        {
            case RectTramsformProperty.Pivot_x:
                anim.rectTransform.pivot = new Vector2(val, anim.rectTransform.pivot.y);
                break;

            case RectTramsformProperty.Pivot_y:
                anim.rectTransform.pivot = new Vector2(anim.rectTransform.pivot.x, val);
                break;

            case RectTramsformProperty.Rotate:
                anim.rectTransform.localRotation = Quaternion.AngleAxis(val, Vector3.forward);
                break;

            case RectTramsformProperty.Scale_x:
                anim.rectTransform.localScale = new Vector3(val, 0, 0);
                break;

            case RectTramsformProperty.Scale_y:
                anim.rectTransform.localScale = new Vector3(0, val, 0);
                break;

            case RectTramsformProperty.Scale_z:
                anim.rectTransform.localScale = new Vector3(0, 0, val);
                break;

            case RectTramsformProperty.Scale_xyz:
                anim.rectTransform.localScale = new Vector3(val, val, val);
                break;
        }
    }
}
